$:.unshift File.join(File.dirname(__FILE__), "..","..","m")

require 'test/unit'
require 'informer'

class InformerTest < Test::Unit::TestCase
	include Informer

	class Warner
		
		def initialize(informer)
			informer.add_observer(self)		  
		end
		def update(infor)
			puts "Informer changed with notice: #{infor.notice?.to_s}"
		end
	end


	def setup
		@w = Warner.new(self)
	end

	def teardown
	end

	def test_state
		Informer::STATES.each {|s| assert_equal(s, self.state=s)}
	end

	def test_state?
		Informer::STATES.each do |s|
			self.state= s
			assert_equal(s, self.state?)
		end
	end

	def test_notice
		self.add_notice 'one'
		self.add_notice 'two'
		assert_equal(['one','two'], notice?)
	end

	def test_clear
		self.state=Informer::ERROR
		self.add_notice 'test clear'
		clear!
		assert_equal(Informer::UNDEFINED,self.state?)
		assert_equal([],notice?)
	end

end
